﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace KTV项目
{
    public partial class gaidong : Form
    {
        Bestdao dao = new Bestdao();
        public gaidong()
        {
            InitializeComponent();
        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {

        }

        string lujing;
        private void but_Click(object sender, EventArgs e)
        {
            //点击浏览按钮后打开选择文件
            OpenFileDialog od = new OpenFileDialog();
            od.InitialDirectory = "D:\\Songs";
            od.Filter = "mp3|*.mp3|mp4|*.MP4|mpg|*.mpg";
            DialogResult dr = od.ShowDialog();

            if (dr == DialogResult.OK)
            {
                lujing = od.FileName;
                texturl.Text = lujing;
            }
        }

        private void gaidong_Load(object sender, EventArgs e)
        {
            //将数据库的数据绑定到下拉框中
            string sql = "select songtype_id,songtype_name from song_type";
            comtype.DataSource = dao.table(sql);
            comtype.DisplayMember = "songtype_name";
            comtype.ValueMember = "songtype_id";
        }

        private void button1_Click(object sender, EventArgs e)
        {
            //将数据带入数据库进行修改
            string sql = string.Format(@"update song_info set song_name='{0}',song_ab='{1}',songtype_id={2},song_url='{3}'
where song_id = {4}",texname.Text,texpin.Text,comtype.SelectedIndex+1,texturl.Text,texid.Text);
            int he = dao.query(sql);
            if (he!=0)
            {
                //判断修改结果是否成功
                MessageBox.Show("修改成功","提示");
                //修改成功之后关闭本窗体
                this.Close();
            }
            else
            {
                MessageBox.Show("修改失败","提示");
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            //执行完毕后关闭本窗体
            this.Close();
        }
    }
}
